package com.code.AZPlan.service.web;

import com.code.AZPlan.api.AZPlanStaticIncomeService;
import com.code.AZPlan.client.AZPlanStaticIncomeClient;
import com.code.AZPlan.model.bo.*;
import com.code.AZPlan.model.po.*;
import com.code.commons.service.impl.RestfulCrudServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * AZ计划静态收益服务实现
 *
 * @author tangyifei
 * @since 2019年12月20日17:51:24
 */
@Slf4j
@RestController("AZPlanStaticIncomeClientService")
@RequestMapping("/AZPlanStaticIncomes")
public class AZPlanStaticIncomeClientService extends RestfulCrudServiceImpl<AZPlanBalance, String> implements AZPlanStaticIncomeClient {

    @Resource
    private AZPlanStaticIncomeService azPlanStaticIncomeService;

    @GetMapping("/reload-account-tree")
    public void reloadAccountTree() {
        azPlanStaticIncomeService.reloadAccountTree();
    }

    @PostMapping("/money-transfer")
    public MoneyTransferRecord moneyTransfer(@RequestBody MoneyTransferRecord moneyTransferRecord) {
        return azPlanStaticIncomeService.moneyTransfer(moneyTransferRecord);
    }

    @PostMapping("/exchange")
    public ExchangeFlow insertExchangeFlow(@RequestBody ExchangeFlow exchangeFlow) {
        return azPlanStaticIncomeService.insertExchangeFlow(exchangeFlow);
    }

    @PatchMapping("/entry-money")
    public EntryMoneyBO entryMoney(@RequestBody EntryMoneyBO entryMoneyBO) throws Exception {
        return azPlanStaticIncomeService.entryMoney(entryMoneyBO);
    }

    @GetMapping("/{userId}/balance")
    public AZPlanBalance getAZPlanBalanceByUserId(@PathVariable("userId") String userId) {
        return azPlanStaticIncomeService.getAZPlanBalanceByUserId(userId);
    }

    @GetMapping("/{userId}/get-money-transfer")
    public MoneyTransferRecord getMoneyTransferByUserIdAndCoinType(@PathVariable("userId") String userId, @RequestParam(value = "coinType", required = false) String coinType,
                                                                   @RequestParam(value = "coinAddress", required = false) String coinAddress,
                                                                   @RequestParam(value = "transferType", required = false) Integer transferType) {
        return azPlanStaticIncomeService.getMoneyTransferByUserIdAndCoinType(userId, coinType, coinAddress, transferType);
    }

    @GetMapping("/get-ore-pool")
    public Map<String, Object> getOrePool(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType) {
        return azPlanStaticIncomeService.getOrePool(userId, coinType);
    }

    @GetMapping("/get-total-income-amount")
    public BigDecimal getTotalIncomeAmount(@RequestParam("userId") String userId) {
        return azPlanStaticIncomeService.getTotalIncomeAmount(userId);
    }

    @GetMapping("/get-total-xwc-amount")
    public BigDecimal getTotalXWCAmount(@RequestParam("userId") String userId) {
        return azPlanStaticIncomeService.getTotalXWCAmount(userId);
    }

    @GetMapping("/get-total-btc-amount")
    public BigDecimal getTotalBTCAmount(@RequestParam("userId") String userId) {
        return azPlanStaticIncomeService.getTotalBTCAmount(userId);
    }

    @GetMapping("/get-total-exchange-amount")
    public BigDecimal getTotalExchangeAmount(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType) {
        return azPlanStaticIncomeService.getTotalExchangeAmount(userId, coinType);
    }

    @GetMapping("/get-total-wallet-amount")
    public BigDecimal getTotalWalletAmount(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType) {
        return azPlanStaticIncomeService.getTotalWalletAmount(userId, coinType);
    }

    @GetMapping("/{userId}/incomes")
    public Map<String, Object> getIncomes(@PathVariable("userId") String userId, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "pageSize", required = false) Integer pageSize) throws Exception {
        return azPlanStaticIncomeService.getIncomes(userId, page, pageSize);
    }

    @GetMapping("/{userId}/usd-bills")
    public Map<String, Object> getUsdBills(@PathVariable("userId") String userId, @RequestParam("coinType") String coinType,
                                           @RequestParam(value = "page", required = false) Integer page,
                                           @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return azPlanStaticIncomeService.getUsdBills(userId, coinType, page, pageSize);
    }

    @GetMapping("/get-az-plan-wallet")
    public AZPlanWallet getAZPlanWallet(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType) {
        return azPlanStaticIncomeService.getAZPlanWallet(userId, coinType);
    }

    @GetMapping("/get-transfer-in-out-flow-list")
    public List<TransferInOutFlow> getTransferInOutFlowList(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType,
                                                            @RequestParam(value = "flowType", required = false) Integer flowType) {
        return azPlanStaticIncomeService.getTransferInOutFlowList(userId, coinType, flowType);
    }

    @PostMapping("/withdraw")
    public int withdraw(@RequestBody WithdrawOrder withdrawOrder) {
        return azPlanStaticIncomeService.withdraw(withdrawOrder);
    }

    @GetMapping("/get-total-money-transfer-amount")
    public BigDecimal getTotalMoneyTransferAmount(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType, @RequestParam("transferType") Integer transferType) {
        return azPlanStaticIncomeService.getTotalMoneyTransferAmount(userId, coinType, transferType);
    }

    @GetMapping("/get-withdraw-order")
    public List<WithdrawOrder> getWithdrawOrderList(@RequestParam(value = "userId", required = false) String userId, @RequestParam(value = "coinType", required = false) String coinType) {
        return azPlanStaticIncomeService.getWithdrawOrderList(userId, coinType);
    }

    @GetMapping("/get-usdt-ore-pool-version")
    public List<UserRelativeVersionBO> getUserRelativeVersionBOList(@RequestParam("userId") String userId) {
        return azPlanStaticIncomeService.getUserRelativeVersionBOList(userId);
    }

    @GetMapping("/get-all-user-ore-pool-version")
    public List<AZPlanBalance> getUserOrePoolVersionList() {
        return azPlanStaticIncomeService.getUserOrePoolVersionList();
    }

    @GetMapping("/get-entry-money-flow-list")
    public List<EntryMoneyFlow> getEntryMoneyFlowList() {
        return azPlanStaticIncomeService.getEntryMoneyFlowList();
    }

    @PostMapping("/wallets/get-withdraw-list")
    public WithdrawBO getWithdrawList(@RequestBody WithdrawBO withdrawBO) {
        return azPlanStaticIncomeService.getWithdrawList(withdrawBO);
    }

    /**
     * 获取提币订单
     *
     * @return 提币订单
     */
    @GetMapping("/wallets/get-withdraw-order")
    public WithdrawOrder getWithdrawOrder(String id) {
        return azPlanStaticIncomeService.getWithdrawOrder(id);
    }

    @PatchMapping("/update-withdraw-order")
    public int updateWithdrawOrder(@RequestBody WithdrawOrder withdrawOrder) {
        return azPlanStaticIncomeService.updateWithdrawOrder(withdrawOrder);
    }

    @GetMapping("/generate-static-income")
    public void generateStaticIncome() {
        azPlanStaticIncomeService.generateStaticIncome();
    }

    @GetMapping(value = "/manual-print-memory-tree")
    public String manualPrintMemoryTree(String userId) {
        return azPlanStaticIncomeService.manualPrintMemoryTree(userId);
    }

    @GetMapping("/get-all-child-account-total-entry-amount")
    public BigDecimal getAllChildAccountTotalEntryAmount(String userId) {
        return azPlanStaticIncomeService.getAllChildAccountTotalEntryAmount(userId);
    }

    @GetMapping("/get-indirect-children-recommends")
    public Map<String, Object> getIndirectRecommends(String parentId, Integer entryMoneyState, Integer page, Integer pageSize) {
        return azPlanStaticIncomeService.getIndirectRecommends(parentId, entryMoneyState, page, pageSize);
    }

    /**
     * 获取充值列表
     *
     * @param rechargeTranBO 充值记录对象
     * @return 充值列表
     */
    @PostMapping("/wallets/get-deposit-list")
    public RechargeTranBO getDepositList(@RequestBody RechargeTranBO rechargeTranBO) {
        return azPlanStaticIncomeService.getDepositList(rechargeTranBO);
    }

    /**
     * 获取用户资产列表
     *
     * @param userAssetBO 用户资产业务对象
     * @return 用户资产列表
     */
    @PostMapping("/wallets/get-user-assets")
    public UserAssetBO getUserAssetList(@RequestBody UserAssetBO userAssetBO) {
        return azPlanStaticIncomeService.getUserAssetList(userAssetBO);
    }

    /**
     * 标记内部用户
     *
     * @param userId 用户Id
     */
    @PatchMapping("/markInnerUser")
    public void markInnerUser(String userId) {
        azPlanStaticIncomeService.markInnerUser(userId);
    }

    /**
     * 获取入金列表
     *
     * @param entryMoneyFlowBO 用户入金流水业务对象
     * @return 用户入金列表
     */
    @PostMapping("/wallets/get-entry-money-list")
    public EntryMoneyFlowBO getEntryMoneyFlowList(EntryMoneyFlowBO entryMoneyFlowBO) {
        return azPlanStaticIncomeService.getEntryMoneyFlowList(entryMoneyFlowBO);
    }

    /**
     * 获取兑换流水列表
     *
     * @param exchangeFlowBO 用户兑换流水业务对象
     * @return 用户兑换列表
     */
    @PostMapping("/wallets/get-exchange-list")
    public ExchangeFlowBO getExchangeFlowList(ExchangeFlowBO exchangeFlowBO) {
        return azPlanStaticIncomeService.getExchangeFlowList(exchangeFlowBO);
    }

    /**
     * 获取收益统计日报列表
     *
     * @param incomeStatisticsDailyBO 收益统计日报业务对象
     * @return 收益统计日报列表
     */
    @PostMapping("/wallets/get-income-statistics-list")
    public IncomeStatisticsDailyBO getIncomeStatisticsList(@RequestBody IncomeStatisticsDailyBO incomeStatisticsDailyBO) {
        return azPlanStaticIncomeService.getIncomeStatisticsList(incomeStatisticsDailyBO);
    }

    /**
     * 获取收益明细列表
     *
     * @param incomeStatisticsDailyBO 收益统计日报业务对象
     * @return 收益明细列表
     */
    @PostMapping("/wallets/get-income-detail-list")
    public IncomeStatisticsDailyBO getIncomeDetailList(@RequestBody IncomeStatisticsDailyBO incomeStatisticsDailyBO) {
        return azPlanStaticIncomeService.getIncomeDetailList(incomeStatisticsDailyBO);
    }

    /**
     * 站内转账
     *
     * @param inSiteUserBO 站内转账业务对象
     * @return 影响的行数
     */
    @PostMapping("/in-site-transfer")
    public int inSiteTransfer(@RequestBody InSiteUserBO inSiteUserBO) {
        return azPlanStaticIncomeService.inSiteTransfer(inSiteUserBO);
    }

    /**
     * 根据用户主键和币种类型获取未审核的（冻结的）的提币总金额
     *
     * @param userId   用户主键
     * @param coinType 币种类型
     * @return 冻结的金额
     */
    @Override
    public BigDecimal getFrozenAmount(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType) {
        return azPlanStaticIncomeService.getFrozenAmount(userId, coinType);
    }


    /**
     * 添加公告
     *
     * @param azNotice 公告对象
     * @return 影响的行数
     */
    @PostMapping("/notices")
    public int addAzNotice(@RequestBody AzNotice azNotice) {
        return azPlanStaticIncomeService.addAzNotice(azNotice);
    }

    /**
     * 修改公告
     *
     * @param azNotice 公告对象
     * @return 影响的行数
     */
    @PatchMapping("/notices")
    public int updateAzNotice(@RequestBody AzNotice azNotice) {
        return azPlanStaticIncomeService.updateAzNotice(azNotice);
    }

    /**
     * 根据公告主键查询单个公告
     *
     * @param id 主键
     * @return 公告对象
     */
    @GetMapping("/notices/{id}")
    public AzNotice getAzNoticeById(@PathVariable("id") String id) {
        return azPlanStaticIncomeService.getAzNoticeById(id);
    }

    /**
     * 根据相关的检索条件获取公告列表
     *
     * @param azNoticeBO 公告业务对象
     * @return 公告业务对象
     */
    @PostMapping("/notices/get-notice-list")
    public AzNoticeBO getAzNoticeList(@RequestBody AzNoticeBO azNoticeBO) {
        return azPlanStaticIncomeService.getAzNoticeList(azNoticeBO);
    }

    /**
     * 修改公告的上线与下线状态
     *
     * @param azNotice 公告对象
     * @return 影响的行数
     */
    @PatchMapping("/notices/up-down")
    public int upDownAzNotice(@RequestBody AzNotice azNotice) {
        return azPlanStaticIncomeService.upDownAzNotice(azNotice);
    }

}
